package com.yoomiito.app.ui.my.remain.transfer;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.View;
import android.widget.TextView;

import com.yoomiito.app.Constant;
import com.yoomiito.app.R;
import com.yoomiito.app.adapter.ViewPagerFragmentAdapter;
import com.yoomiito.app.base.BaseActivity;
import com.yoomiito.app.model.my.PayeeInfo;
import com.yoomiito.app.ui.my.psw.ChangeResultFragment;
import com.yoomiito.app.utils.L;
import com.yoomiito.app.widget.NoScrollViewPager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class TransferActivity extends BaseActivity {

    @BindView(R.id.tv_center)
    TextView mTitleView;
    @BindView(R.id.noViewPager)
    NoScrollViewPager mNoScrollViewPager;
//    @BindView(R.id.frameLayout)
//    FrameLayout mFrameLayout;
    private List<Fragment> mFragments = new ArrayList<>();

    @Override
    public int getLayoutId() {
        return R.layout.act_transfer;
    }

    @Override
    public Object newP() {
        return null;
    }

    public static void start(Context context){
        Intent intent = new Intent(context,TransferActivity.class);
        context.startActivity(intent);
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
//        AndroidBug5497Workaround.assistActivity(this);
//        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

        mTitleView.getPaint().setFakeBoldText(true);
        mTitleView.setText("转账");
        mTitleView.setVisibility(View.VISIBLE);
        mFragments.add(new InputTelFragment());
        mFragments.add(new TransferFragment());
        ChangeResultFragment changeResultFragment = new ChangeResultFragment();
        Bundle bundle = new Bundle();
        bundle.putString(Constant.MSG,"转账成功");
        changeResultFragment.setArguments(bundle);
        mFragments.add(changeResultFragment);
//        FragmentManager fm = getSupportFragmentManager();
//        FragmentTransaction transaction = fm.beginTransaction();
//        transaction.add(R.id.frameLayout,new InputTelFragment());
//        transaction.commitAllowingStateLoss();
        mNoScrollViewPager.setAdapter(new ViewPagerFragmentAdapter(getSupportFragmentManager(),mFragments));
    }

    @OnClick({R.id.iv_back_left})
    public void onClick(View view){
        if (view.getId()==R.id.iv_back_left){
            if (mNoScrollViewPager!=null){
                int i = mNoScrollViewPager.getCurrentItem();
                if (i==0||i == 2){
                    finish();
                } else {
                    mNoScrollViewPager.setCurrentItem(i-1);
                }
            }else {
                finish();
            }
        }
    }

    public void setTransferData(PayeeInfo payeeInfo){
        L.i("P: "+payeeInfo);
        TransferFragment transferFragment = (TransferFragment) mFragments.get(1);
        Bundle bundle = new Bundle();
        bundle.putParcelable(Constant.DATA,payeeInfo);
        transferFragment.setArguments(bundle);
    }

    public void switchFm(int position){
        mNoScrollViewPager.setCurrentItem(position);
    }
}
